<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<h1>1</h1>
<h2>1</h2>
<h3>1</h3>
<h4>1</h4>
<h5>1</h5>
<h6>1</h6>

<script>
    let count = 0;
    //开启定时器
    setInterval(function () {
        count++;
        let h1 = document.querySelector("h1")
        h1.innerText = count + "s"
    }, 1000);//每秒执行一次

    //开启定时器第二种写法
    function f() {
        count++;
        let h1 = document.querySelector("h2")
        h1.innerText = count + "s"
    }
    //当方法作为参数进行传递时不写()
    setInterval(f,1000);//每隔一秒执行一次

停止定时器
    let count = 0;
    function f() {
        count++;
        if(count>10){//当count大于10停止定时器
            clearInterval(timer)
        }
        let h1 = document.querySelector("h2")
        h1.innerText = count + "s"
    }
    //当方法作为参数进行传递时不写()
    let timer=setInterval(f,1000);//每隔一秒执行一次



   开启只执行一次的定时器
    setInterval(function () {
        alert("时间到")
    },5000)//五秒后停止
// ---------------------------------------------------------------------


    let count = 0;
    let h = 0;
    //开启定时器,实现时间每隔60秒自动清零,分钟数自动+1
    setInterval(function () {
        count++;
        let h1 = document.querySelector("h3")
        let h2 = document.querySelector("h4")
        if (count > 60) {
            count = 0;
            h++;
            h2.innerText = h;
        }
        h1.innerText = count + "s"
    }, 1000);//每秒执行一次

    //第二种写法
    let count = 0;//秒数
    let h = 0;//分钟
  function f1() {
        count++;
        let h1 = document.querySelector("h5")
        let h2 = document.querySelector("h6")
        if (count > 60) {
            count = 0;
            h++;
            h2.innerText = h;
        }
        h1.innerText = count + "s"
    };
  setInterval(f1,1000)//每隔一秒执行一次


</script>
</body>
</html>